package component.fulltextsearch.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


/**
 * Properties文件装载器类
 */
public class PropertiesUtil {
    
	/**
     * Properties文件装载器实例。
     */
    private static PropertiesUtil propertiesLoader = null;
	/**
    * 
    * 构造函数
    */
	private PropertiesUtil() {	
		
	}
	/**
	 * 获得平台无关的properties对象。
	 * @param argFileName
	 * @return
	 * @throws FileNotFoundException
	 */
	public synchronized Properties getProperties(String argFileName)
	    throws FileNotFoundException {
		    InputStream in =ClassLoaderUtil.getResourceAsStream(argFileName + ".properties", this.getClass());		   
		    Properties properties = new Properties();
		    if (in != null) {                
		    	try {
					properties.load(in);
				} catch (IOException e) {			
					e.printStackTrace();
				}               
            }		 
		return properties;
	}
	
	/**
	 * 单子设计模式。
	 * @return
	 */
	public static PropertiesUtil getInstance() {
		if (propertiesLoader == null) {	
			propertiesLoader = new PropertiesUtil();
		}
		return propertiesLoader;
	}
	
	public static void main(String[] args) {
		try {
			Properties pop = PropertiesUtil.getInstance().getProperties("fulltextsearch");
			System.out.println(pop);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
